// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MovePage.java

package com.kaylyn.item;

import java.awt.Point;

import com.kaylyn.util.Initializable;
import com.kaylyn.util.Resource;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

public class MovePage extends JScrollPane implements Initializable {

	public MovePage() {
		setSize(840, 560);
		getViewport().setLayout(null);
		setOpaque(true);
		getViewport().setOpaque(true);
		setBorder(BorderFactory.createEmptyBorder());
		setVerticalScrollBarPolicy(21);
		setHorizontalScrollBarPolicy(31);

		label = new JLabel();
		ImageIcon icon = new ImageIcon(Resource.loadImage("38987.jpg"));
		label.setSize(icon.getIconWidth(), icon.getIconHeight());
		label.setIcon(icon);

	}

	public void start() {
		getViewport().setView(label);
		Runnable r = new Runnable() {

			@Override
			public void run() {
				while (flag) {
					if (state){
						position.y += 1;
						if(position.y == label.getHeight()-getHeight())
							state = false;
					}
					else{
						position.y -= 1;
						if(position.y == 0)
							state = true;
					}
					SwingUtilities.invokeLater(new Runnable() {

						@Override
						public void run() {
							getViewport().setViewPosition(position);
							repaint();
						}
					});

					try {
						Thread.sleep(12);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		};
		new Thread(r).start();
	}

	public void stop() {
		flag = false;
	}

	private static final long serialVersionUID = 1L;
	private boolean flag = true;
	private boolean state = true;
	private Point position = new Point(0, 0);
	private JLabel label;
}
